package com.cn.lf.wx;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.cn.lf.wx.compent.AppFiler;
import com.cn.lf.wx.compent.AppHandlerInterceptor;

@Configuration
public class AppConfig extends WebMvcConfigurerAdapter {

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
//  registry.addInterceptor(new AppHandlerInterceptor()).addPathPatterns(
//    "/app/**","/wxgzh/**");
		registry.addInterceptor(new Authconfig()).addPathPatterns("**").excludePathPatterns("/admin/auth/menus",
				"/admin/auth/menus/role","/admin/auth/roles","/admin/login","/admin/token");
		super.addInterceptors(registry);
	}

	@Override
	public void addCorsMappings(CorsRegistry registry) {
		// 设置允许跨域的路由
		registry.addMapping("/**")
				// 是否允许cookies
				.allowCredentials(true)
				// 设置允许跨域请求的域名
				.allowedOrigins("*")
				// 放行哪些请求方式 * 代表允许所有方式
				.allowedMethods("*")
				// 放行哪些原始请求头部信息
				.allowedHeaders("*")
				// 跨域允许时间
				.maxAge(3600);
	}

	@Bean
	public FilterRegistrationBean myOncePerRequestFilterRegistration() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setFilter(new AppFiler());
		registration.addUrlPatterns("/*");// 拦截路径
		registration.setName("AppFiler");// 拦截器名称
		registration.setOrder(1);// 顺序
		return registration;
	}

}